import { _decorator, Component, Node } from "cc";
const { ccclass, property } = _decorator;
import { User } from "./user/User";
import * as Http from "./lib/Request";
import { Utils } from "./utils/utils";
import type { Util } from "./utils/utils";
import { Audio } from "./lib/Audio";
import { Socket } from "./lib/Socket";
import { RequestType } from "./lib/Request";
import { GameNet } from "./lib/GameNet";
import { Alert } from "./components/Alert";
import { WaitngConnect } from "./components/WaitngConnect";
interface SI {
  appweb?: string;
  hall?: string;
  [key: string]: any;
}
export class MyGlobal {
  userMgr: User;
  http: RequestType;
  audio: Audio;
  utils: Util;
  socket: Socket;
  gameNet: GameNet;
  alert: Alert;
  wc: WaitngConnect;
  // gameNetMgr: GameNet;
  SI: SI;
  constructor() {
    let SI = cc.sys.localStorage.getItem("SI");
    if (SI) {
      try {
        SI = JSON.parse(SI || '{}');
        if (SI.account) {
          Http.setURL("http://" + SI.account);
        }
        console.log(SI, "?SI")
        this.SI = SI;
      } catch (err) {
        this.SI = {};
      }
    }
    this.userMgr = new User();
    let audio = new Audio();
    this.audio = audio;
    this.http = Http;
    this.socket = new Socket();
    this.utils = Utils;
    this.gameNet = new GameNet();
  }
  start() { }

  update(deltaTime: number) { }
}
let myGlobal: MyGlobal;
export function getGlobal() {
  if (!myGlobal) {
    myGlobal = new MyGlobal();
  }
  return myGlobal;
}
